package com.xiezc.controller;

import com.xiezc.EurakeClientApplication;
import com.xiezc.dto.Spider;
import com.xiezc.service.XCrawler;
import com.xiezc.util.XUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class DcController {

    private static final Logger log = LoggerFactory.getLogger(EurakeClientApplication.class);


    @Resource
    private XCrawler xCrawler;

    @RequestMapping("stop")
    public String stop() {
        XUtil.stop = true;
        return "success";
    }

    @RequestMapping("start")
    public String start(Integer param,String[] urls) {
        log.info("start =============================="+ urls );
        for(String url: urls){
            xCrawler.start(url);
        }
        if (param == null) {
            xCrawler.fetchThread();
            xCrawler.praseThread();
            xCrawler.saveThread();
            return "all+";
        }
        if (param == 1) {
            xCrawler.fetchThread();
            return "fetchThread+1";
        }
        if (param == 2) {
            xCrawler.praseThread();
            return "praseThread+1";
        }
        if (param == 3) {
            xCrawler.saveThread();
            return "saveThread+1";
        }
        return null;
    }


}